<template>
  <div class="fix-setting">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <h2>申请记录</h2>
        </div>
      </template>
      <el-table :data="filterTableData" style="width: 100%" border :loading="loading">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="设备名称" width="180" />
        <el-table-column prop="type" label="申请类型" width="120" />
        <el-table-column prop="remarks" label="备注" />
        <el-table-column prop="updated_at" label="更新时间" width="180">
          <template #default="scope">
            {{ formatDate(scope.row.updated_at) }}
          </template>
        </el-table-column>
        <el-table-column prop="applicanter" label="申请人" width="120" />
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'

const tableData = ref([])
const filterTableData = ref([])
const loading = ref(true)

// 格式化日期
const formatDate = (dateString) => {
  const date = new Date(dateString)
  return date.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  })
}

// 获取维修申请数据
const getFixData = async () => {
  loading.value = true
  try {
    const response = await axios.get('http://localhost:8080/api/v1/admin/GetAllReview')
    if (response.data.code === 200) {
      tableData.value = response.data.data
      // 显示所有记录
      filterTableData.value = tableData.value
    }
  } catch (error) {
    ElMessage.error('获取申请记录失败')
    console.error(error)
  } finally {
    loading.value = false
  }
}

onMounted(async () => {
  await getFixData()
})
</script>

<style lang="less" scoped>
.fix-setting {
  padding: 20px;

  .box-card {
    width: 100%;
    margin-bottom: 20px;
  }

  .card-header {
     display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  }
}
.card-header h2 {
  margin: 0;
  color: #303133;
}

</style>